package app

import (
	"chatgpt/model/base"
	"github.com/slclub/go-tips"
	"time"
)

type Recharge struct {
	base.ModelID
	//UUID string `gorm:"size:128;column:uuid;comment:UUID"`
	base.UUIDR
	Belong   string `gorm:"size:128;comment:所属模块"`
	BelongID string `gorm:"size:128;column:belong_id;comment:所属模块"`
	Amount   int    `gorm:"type:int(10);comment:充值金额，分"`
	Remark   string `gorm:"size:128;comment:描述用途"`
	base.ModelTime
}

func (self *Recharge) TableName() string {
	return "gpt_recharge"
}

func (self *Recharge) ConvFromMap(m map[string]any) {
	self.ModelID.ConvFromMap(m)
	self.UUIDR.ConvFromMap(m)
	if val, ok := m["Belong"]; ok {
		self.Belong = tips.String(val)
	}
	if val, ok := m["BelongID"]; ok {
		self.BelongID = tips.String(val)
	}
	if val, ok := m["Amount"]; ok {
		self.Amount = tips.Int(val)
	}
	if val, ok := m["Remark"]; ok {
		self.Remark = tips.String(val)
	}
	self.ModelTime.ConvToMap(m)
}

func (self *Recharge) ConvToMap() map[string]any {
	rtn := map[string]any{
		"ID":       self.ID,
		"UUID":     self.UUID,
		"Belong":   self.Belong,
		"BelongID": self.BelongID,
		"Amount":   self.Amount,
	}
	self.ModelTime.ConvToMap(rtn)
	return rtn
}

// 支付结果
type PayResult struct {
	SerialNo string    // app 订单号
	PlatNo   string    // 第三方平台订单号
	PayType  string    // 付费方法
	Amount   int       // 支付金额
	Ext      string    // 支付自定义参数
	UUID     string    // 主角
	Time     time.Time // 平台支付时间
}

func (self *PayResult) ConvToMap() map[string]any {
	rtn := map[string]any{
		"SerialNo": self.SerialNo,
		"PlatNo":   self.PlatNo,
		"PayType":  self.PayType,
		"Amount":   self.Amount,
		"Ext":      self.Ext,
		"Time":     self.Time,
		"UUID":     self.UUID,
	}
	return rtn
}
